<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>案源环节-案源信息查询</title>
    <link rel="stylesheet" href="/layui/v10/layui.css">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header"></div>
                <div class="layui-card-body">
                    <form class="layui-form">
                        <div class="layui-row" style="margin: 10px 0 0 10px">
                            <button type="button" class="layui-btn" id="inport">导入纳税人识别号</button>
                            <button type="button" class="layui-btn" id="export">导出当前数据</button>
                        </div>
                        <div style="margin-left: 10px">
                            <table class="layui-table" id="ayxxTable" lay-filter="ayxxTable"></table>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layui/v10/layui.js"></script>
<script src="/js/core.util.js"></script>
<script th:inline="none">
    // 获取token
    const token = CoreUtil.getData("access_token");
    // 地址栏转义token中的#号
    const tokenQuery = token.replace("#", "%23");
    const table = layui.table;
    const form = layui.form;
    const layer = layui.layer;
    const $ = jQuery = layui.jquery;
    const laydate = layui.laydate;
    const upload = layui.upload;
    const element = layui.element;
    let ayxxTableIns;
    let ayxxAllData = null;
    layui.use(['table', 'layer', 'laydate', 'upload', 'element'], function () {
        // 案源信息表
        ayxxTableIns = table.render({
            elem: '#ayxxTable',
            contentType: 'application/json',
            headers: {
                "authorization": token
            },
            page: true, // 开启分页
            url: '', //数据接口
            data: [],
            method: 'POST',
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null
                        : CoreUtil.paramsDecrypt(res.data.records)
                }
            },
            cols: [[
                {align: 'center', width: 200, field: 'nsrsbh', title: '纳税人识别号', sort: true},
                {align: 'center', width: 320, field: 'nsrmc', title: '纳税人名称', sort: true},
                {align: 'center', width: 180, field: 'jcajbh', title: '稽查案件编号', sort: true},
                {align: 'center', width: 280, field: 'zgswjgmc', title: '主管税务机关', sort: true},
                {align: 'center', width: 260, field: 'zgswskmc', title: '主管税务所科名称', sort: true},
                {align: 'center', width: 120, field: 'nsrztmc', title: '纳税人状态', sort: true,},
                {align: 'center', width: 200, field: 'kqccsztdjbz', title: '跨区域财产税主体标识', sort: true},
                {align: 'center', width: 180, field: 'ajztmc', title: '案件状态', sort: true},
                {
                    field: 'larq', title: '立案日期', align: 'center', width: 120,
                    sort: true,
                    templet: function (d) {
                        if (!d.larq) {
                            return '';
                        }
                        return layui.util.toDateString(d.larq, 'yyyy-MM-dd');
                    }
                },
                {
                    field: 'jarq', title: '结案日期', align: 'center', width: 120,
                    sort: true,
                    templet: function (d) {
                        if (!d.jarq) {
                            return '';
                        }
                        return layui.util.toDateString(d.jarq, 'yyyy-MM-dd');
                    }
                },
                {align: 'center', width: 160, field: 'sfczzcay', title: '是否存在在查案源', sort: true},

            ]],
            toolbar: '#toolbar',
        });
        //导出
        $("#export").click(function () {
            layer.confirm('确定导出所有数据?', {icon: 3, title: '提示'}, function (index) {
                let allData = ayxxAllData;
                if (!allData || allData.length === 0) {
                    return layer.alert('暂无数据可导出！', {icon: 2});
                }
                //全部导出
                table.exportFile(ayxxTableIns.config.id, allData, 'xlsx', "案源信息表")
                //导出时阻止页面刷新
                $(".layui-form").submit(function (e) {
                    e.preventDefault();
                })

                layer.close(index);
            });
        });
        // 文件上传配置
        upload.render({
            elem: '#inport', // 绑定按钮
            headers: {"authorization": token},
            url: '/workflow/casesource/uploadAyxxcxExcel',  // 上传接口地址
            accept: 'file',       // 允许上传的文件类型
            exts: 'xlsx|xls',     // 允许上传的文件后缀
            before: function () {
                layer.load(); //上传loading
            },
            done: function (res) {
                clearTable();
                if (res.code === 0) {
                    ayxxTableIns.reload({
                        contentType: 'application/json',
                        data: res.data.records, // 重新渲染数据
                        url: "",
                        page: {
                            curr: 1
                        }
                    });
                    ayxxAllData = res.data.records;
                } else {
                    layer.alert(res.msg, {icon: 2});
                }
                layer.closeAll('loading'); //关闭loaWding
            },
            error: function () {
                layer.msg('上传失败', {icon: 2});
                layer.closeAll('loading'); //关闭loading
            }
        });
    });

    function clearTable() {
        ayxxAllData = null;
        table.reload('ayxxTable', {
            data: [], // 空数据
            url: '', // 清空数据源
            page: {curr: 1}, // 重置页码
        });
    }

</script>

</body>
</html>




